package pl.edu.agh.iosr.gamblingzone.dao.ejb;

import java.util.List;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import pl.edu.agh.iosr.gamblingzone.dao.UserDAO;
import pl.edu.agh.iosr.gamblingzone.model.User;

@Stateless
public class UserDAOBean extends GenericEJBDAO<User, Long> implements UserDAO {

	
//	@TransactionAttribute(TransactionAttributeType.REQUIRED)
	public User findByLogin(String login) {
		List<User> users = findAll();
		
		if(users.size() == 0) {
			return null;
		}
		else {
			return users.get(0);
		}	
	}

//	@TransactionAttribute(TransactionAttributeType.REQUIRED)
	public boolean authenticateUser(String login, String password) {
		
		User user = findByLogin(login);
		if(user == null) {
			return false;
		}
		//if(!user.getPassword().equals(User.computeSHA1(password))) {
		if(! ((user.getPassword()).equals(password)) ) {
			return false;
		}
		
		return true;
	}

}
